An Exact Arithmetic Package for Ml
نویسنده
چکیده
We present the design and implementation of an exact rational arithmetic package for the programming language Caml, an ML dialect close to the original LCF-ML. Our arithmetic, written almost entirely in Caml, combines eeciency, power and exibility. For eeciency reasons, the package provides several diier-ent basic types to represent numbers, and to reinforce exibility, it implements many functions operating on these types. To master this complexity and to keep the package as simple as possible for the casual user, we design a super type of numbers which provides easy access to exact arithmetic. Nevertheless, the integration of the package into an existing ML compiler raises interesting problems: rational numbers introduce a new data-type which is not a free algebra. This implies modifying the pattern matching algorithm of ML. The proliferation of basic types forces us to nd a new way to input numbers; existing libraries are not designed for the new numerical types. We must adapt them to the numerical package to avoid a tremendous number of coercions or type clashes; nally, since basic operators operate on many diierent numerical types (the mathematical operation \+" has nine incompatible types in the package) we need a mechanism to reconcile them. We want to use the common mathematical notation for arithmetic expressions in order to maintain program readability. In the following, we brieey describe the Caml implementation of the package and some of the algorithms we use. In particular, suitable normalization of rational numbers is discussed. We then present the super type of numbers and state some of its properties. We present problems and propose solutions to integrate the package into an existing ML compiler. Then we give some interesting examples of numeric computation using the package, and nally we give some benchmarks comparing our arithmetic to other, well-known packages. 1 In defense of a sound arithmetic First of all, we would like to convince the reader that exact arithmetic is a desirable feature for a modern programming language. Hardware limitations to the range of representable integers are well known and, although irritating, overrows and underrows of operations are not too diicult to detect, so that programs may explicitly fail in these cases and never return mathematically unsound results. Evidently, this is not the case for oating point arithmetic: partial results are always rounded oo, and these successive roundoo errors may lead to completely erroneous answers. Yet, when computing with real numbers, …
منابع مشابه
RealLib: an Efficient Implementation of Exact Real Arithmetic
This paper is an introduction to the RealLib package for exact real number computations. The library provides certified accuracy, but tries to achieve this at performance close to the performance of hardware floating point for problems that do not require higher precision. The paper gives the motivation and features of the design of the library and compares it to other packages for exact real a...
متن کاملTowards Exact Geometric Computation
Exact computation is assumed in most algorithms in computational geometry. In practice, implementors perform computation in some fixed-precision model, usually the machine floating-point arithmetic. Such implementations have many well-known problems, here informally called "robustness issues". To reconcile theory and practice, authors have suggested that theoretical algorithms ought to be redes...
متن کاملThe iRRAM: Exact Arithmetic in C++
Abstract: The iRRAM is a very efficient C++ package for errorfree real arithmetic based on the concept of a Real-RAM. Its capabilities range from ordinary arithmetic over trigonometric functions to linear algebra even with sparse matrices. We discuss the concepts and some highlights of the implementation.
متن کاملInterval Arithmetic Using Sse-2 (draft)
We present an implementation of double precision interval arithmetic using the single-instruction-multiple-data SSE-2 instruction and register set extensions. The implementation is part of a package for exact real arithmetic, which defines the interval arithmetic variation that must be used: incorrect operations such as division by zero cause exceptions, loose evaluation of the operations is in...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2007